﻿@{
    ViewBag.Title = "用户管理";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
@model UserQueryModel
<div class="row">
    <div class="panel panel-default">
        <div class="panel-body">
            <form class="form-inline" role="form" id="searchForm">
            <div class="form-group input-group-sm">
                <label for="name">
                    名称：</label>
                @Html.TextBoxFor(m => m.LoginNo, new { @class = "form-control", placeholder = "请输入名称" })
            </div>
             <div class="form-group input-group-sm">
                <label for="name">
                    角色：</label>
                @Html.DropDownListFor(m => m.RoleId, Model.RoleList, new { @class = "form-control chosen-select", placeholder = "请选择角色" })
            </div>
            <label>
                创建日期：</label>
            <div class="form-group">
                <div class="input-group input-daterange input-group-sm">
                    @Html.TextBoxFor(m => m.StartTime, new { @class = "form-control datepicker", placeholder = "起始时间" })
                    <span class="input-group-addon">到</span>
                    @Html.TextBoxFor(m => m.EndTime, new { @class = "form-control datepicker", placeholder = "结束时间" })
                </div>
            </div>
            @Html.Partial("UC_Button", ViewBag.ButtonList as List<Sys_Menu>)
            </form>
        </div>
    </div>
    <div class="panel panel-default">
        <div class="panel-body">
            <table id="flexigridData">
            </table>
        </div>
    </div>
</div>
@section Customer_Js{
    <script type="text/javascript">
        function flexiQuery() {
            $('#flexigridData').bootstrapTable('refresh');
        }

        function addUser() {
            window.location.href = '@Url.Action("Add", "User")';
            return false;
        }

        function editUser() {
            var row = $('#flexigridData').bootstrapTable('getSelections');
            if (row == null || row.length == 0) {
                BootStrapUI_Core.alertError('请选择需要编辑的行');
            } else {
                window.location.href = '@Url.Action("Edit", "User")?id=' + row[0].Id;
            }
            return false;
        }

        function editUserDistributionAction() {
            var row = $('#flexigridData').bootstrapTable('getSelections');
            if (row == null || row.length == 0) {
                BootStrapUI_Core.alertError('请选择需要分配权限的用户');
            } else {
                window.location.href = '@Url.Action("DistributionAction", "User")?id=' + row[0].Id;
            }
            return false;
        }

        function activeFormatter(value, row, index) {
            if (row.IsActive) {
                return '<span class="label label-info">已激活</span>'
            } else {
                return '<span class="label label-warning">未激活</span>'; 
            };
        }

        $(function () {
            $('#btnQuery').on('click', flexiQuery);
            $('#btnUserAdd').on('click', addUser);
            $('#btnUserEdit').on('click', editUser);
            $('#btnUserDistributionAction').on('click', editUserDistributionAction);

            btTable('#flexigridData', {
                url: '@Url.Action("AjaxIndex", "User")',
                columns: [[
                    { field: 'rowscount', checkbox: true, width: 15 },
                    { field: 'LoginNo', title: '登录账号', width: 100 },
                    { field: 'ShortName', title: '用户名称', width: 100 },
                    { field: 'Contact', title: '联系方式', width: 120 },
                    { field: 'RoleName', title: '角色', width: 100 },
                    { field: 'IsActive', title: '是否激活', width: 100, formatter: activeFormatter },
                    { field: 'CreateTime', title: '创建时间', width: 200 },
                ]]
            });
        })
    </script>
}
